package com.bookstore.dao.impl;

import com.bookstore.dao.OrderItemDao;
import com.bookstore.entity.OrderItem;

import java.util.List;

public class OrderItemDaoImpl implements OrderItemDao {
    @Override
    public int insert(OrderItem orderItem) {
        String sql = "INSERT INTO `T_order_item`(`order_id`,`product_id`,`buynum`) VALUES (?, ?, ?)";
        return 0;
    }

    @Override
    public int delete(Integer orderItemId) {
        String sql = "DELETE FROM `T_order_item` WHERE `order_item_id`=?";
        return 0;
    }

    @Override
    public int update(OrderItem orderItem) {
        int result = 0;
        String sql = "UPDATE `T_order_item` SET";
        StringBuilder sb = new StringBuilder(sql);
        int flag=0;
        if(orderItem==null){
            return result;
        }
        if(orderItem.getOrderId()!=null){
            flag=1;
            sb.append(" `order_id`=?");
        }
        if(orderItem.getProductId()!=null){
            if(flag!=0){
                sb.append(",");
            }
            sb.append(" `product_id`=?");
            flag=1;
        }
        if(orderItem.getBuynum()!=null){
            if(flag!=0){
                sb.append(",");
            }
            sb.append(" `buynum`=?");
            flag=1;
        }
        return 0;
    }

    @Override
    public List<OrderItem> queryOrderItem(OrderItem orderItem) {
        String sql = "SELECT * FROM `T_order_item`WHERE  1=1";
        StringBuilder sb = new StringBuilder(sql);
        if(orderItem.getOrderItemId()!=null){
            sb.append(" AND `order_item_id`=?");
        }
        if(orderItem.getOrderId()!=null){
            sb.append(" AND `order_id`=?");
        }
        if(orderItem.getProductId()!=null){
            sb.append(" AND `product_id`=?");
        }
        if(orderItem.getBuynum()!=null){
            sb.append(" AND `buynum`=?");
        }
        return null;
    }
}
